package com.csdj.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.csdj.config.LogAnnotation;
import com.csdj.entity.Foodlist;
import com.csdj.entity.Result;
import com.csdj.service.IFoodlistService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zq
 * @since 2024-12-11
 */
@RestController
@RequestMapping("/foodlist")
@CrossOrigin
public class FoodlistController {

    private static final Logger log = LoggerFactory.getLogger(FoodlistController.class);
    @Autowired
    private IFoodlistService foodlistService;

    @GetMapping("selectfoodlist")
    public Object selectfoodlist(){
        return foodlistService.list();
    }

    @GetMapping("selectfoodlisttop10")
    public Object selectfoodlisttop10(){
        return foodlistService.selectfoodlistBytop10();
    }

    @GetMapping("selectfoodlistByName")
    public Object selectfoodlistByName(@RequestParam String name){
        return foodlistService.selectfoodlistByName(name);
    }

    @GetMapping("selectfoodlistByCategory")
    public Result selectfoodlistByCategoryPage(@RequestParam( defaultValue = "1") int current, @RequestParam(defaultValue = "10") int size, @RequestParam String categorytype) {
        QueryWrapper<Foodlist> queryWrapper= Wrappers.query();
        if (StringUtils.isEmpty(categorytype)){
            queryWrapper.like("food_type",categorytype);
        }
        Page<Foodlist> page = foodlistService.selectfoodlistByCategory(new Page<>(current, size),categorytype);
        System.out.println("==================================================");
        System.out.println(page);
        return Result.success(page);
    }

    @GetMapping("selectfoodlistDesc")
    public Result selectfoodlistDescPage(@RequestParam( defaultValue = "1") int current, @RequestParam(defaultValue = "10") int size) {
        QueryWrapper<Foodlist> queryWrapper= Wrappers.query();
        Page<Foodlist> page = foodlistService.selectfoodlistDesc(new Page<>(current, size));
        return Result.success(page);
    }

    @GetMapping("selectfoodlistAsc")
    public Result selectfoodlistAscPage(@RequestParam( defaultValue = "1") int current, @RequestParam(defaultValue = "10") int size) {
        QueryWrapper<Foodlist> queryWrapper= Wrappers.query();
        Page<Foodlist> page = foodlistService.selectfoodlistAsc(new Page<>(current, size));
        return Result.success(page);
    }

    @GetMapping("selectCount")
    public int selectCount(){
        int i = foodlistService.selectCount();
        return i;
    }
}
